package net.minecraft.src;

public class LF_ItemSpawner extends Item
{
	public LF_ItemSpawner(int i)
	{
		super(i);
	}

	@Override
	public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l)
	{
		if(itemstack.stackSize == 0)
			return false;

		int i1 = world.getBlockId(i, j, k);
		if(i1 == Block.snow.blockID)
			l = 0;
		else if(i1 != Block.vine.blockID)
		{
			if(l == 0)
				j--;
			if(l == 1)
				j++;
			if(l == 2)
				k--;
			if(l == 3)
				k++;
			if(l == 4)
				i--;
			if(l == 5)
				i++;
		}

		// TODO Commenting these out for the moment, they were mostly useless anyways, need to find out what they became
		/*
		if(!entityplayer.func_35190_e(i, j, k))
			return false;

		if(j == world.field_35472_c - 1 && Block.blocksList[Block.pumpkin.blockID].blockMaterial.isSolid())
			return false;
		*/

		if(world.canBlockBePlacedAt(Block.pumpkin.blockID, i, j, k, false, l))
		{
			if(ModLoader.getMinecraftInstance().isMultiplayerWorld())
				return true;

			itemstack.stackSize--;
			int dmg = itemstack.getItemDamage();
			LF_EntitySeat seat = new LF_EntitySeat(world, i, j, k, dmg);
			seat.setRotation(entityplayer.rotationYaw + 180, 0);

			if(snapRotation)
			{
				double snapRotation = Math.floor((seat.rotationYaw / 90F) + 0.5F);

				seat.setRotation((int)snapRotation * 90, 0);
			}
			
			world.joinEntityInSurroundings(seat);
			seat.setSubType();
			return true;
		}
		else
			return false;
	}

	@Override
	public int getIconFromDamage(int damage)
	{
		if(damage >= mod_LF_GenericFurnitureMain.iconIndexes.length)
			return 0;
		return mod_LF_GenericFurnitureMain.iconIndexes[damage];
	}

	public String getItemNameIS(ItemStack itemstack)
	{
		String itemName = getDamageString(itemstack.getItemDamage());

		return (new StringBuilder()).append(super.getItemName()).append(".").append(itemName).toString();
	}

	public boolean snapRotation = true;
	public final static int numItems = 108;

	public static String getDamageString(int dmg)
	{
		switch(dmg)
		{
			case 0: return "Wooden Chair";
			case 1: return "Wooden High Chair";
			case 2: return "Soft White Chair";
			case 3: return "Soft Orange Chair";
			case 4: return "Soft Magenta Chair";
			case 5: return "Soft Light Blue Chair";
			case 6: return "Soft Yellow Chair";
			case 7: return "Soft Lime Chair";
			case 8: return "Soft Pink Chair";
			case 9: return "Soft Gray Chair";
			case 10: return "Soft Light Gray Chair";
			case 11: return "Soft Cyan Chair";
			case 12: return "Soft Purple Chair";
			case 13: return "Soft Blue Chair";
			case 14: return "Soft Brown Chair";
			case 15: return "Soft Green Chair";
			case 16: return "Soft Red Chair";
			case 17: return "Soft Black Chair";
			case 18: return "Wooden Stand";
			case 19: return "Wooden Table";
			case 20: return "Low Wooden Table";
			case 21: return "High Wooden Table";
			case 22: return "TV";

			// Peripherals 1
			case 23: return "Widescreen TV";
			case 24: return "Wii";
			case 25: return "Xbox 3600";
			case 26: return "PS3";
			case 27: return "DVD Player";

			// Lights 1
			case 28: return "White Lamp";
			case 29: return "Orange Lamp";
			case 30: return "Magenta Lamp";
			case 31: return "Light Blue Lamp";
			case 32: return "Yellow Lamp";
			case 33: return "Lime Lamp";
			case 34: return "Pink Lamp";
			case 35: return "Gray Lamp";
			case 36: return "Light Gray Lamp";
			case 37: return "Cyan Lamp";
			case 38: return "Purple Lamp";
			case 39: return "Blue Lamp";
			case 40: return "Brown Lamp";
			case 41: return "Green Lamp";
			case 42: return "Red Lamp";
			case 43: return "Black Lamp";

			// Deco 1
			case 44: return "White Vase";
			case 45: return "Orange Vase";
			case 46: return "Magenta Vase";
			case 47: return "Light Blue Vase";
			case 48: return "Yellow Vase";
			case 49: return "Lime Vase";
			case 50: return "Pink Vase";
			case 51: return "Gray Vase";
			case 52: return "Light Gray Vase";
			case 53: return "Cyan Vase";
			case 54: return "Purple Vase";
			case 55: return "Blue Vase";
			case 56: return "Brown Vase";
			case 57: return "Green Vase";
			case 58: return "Red Vase";
			case 59: return "Black Vase";

			// Cases 60 - 75 are open

			// Carpets and Drapes 1
			case 76: return "White Curtains";
			case 77: return "Orange Curtains";
			case 78: return "Magenta Curtains";
			case 79: return "Light Blue Curtains";
			case 80: return "Yellow Curtain";
			case 81: return "Lime Curtains";
			case 82: return "Pink Curtains";
			case 83: return "Gray Curtains";
			case 84: return "Light Gray Curtains";
			case 85: return "Cyan Curtains";
			case 86: return "Purple Curtains";
			case 87: return "Blue Curtains";
			case 88: return "Brown Curtains";
			case 89: return "Green Curtains";
			case 90: return "Red Curtains";
			case 91: return "Black Curtains";

			case 92: return "White Carpet";
			case 93: return "Orange Carpet";
			case 94: return "Magenta Carpet";
			case 95: return "Light Blue Carpet";
			case 96: return "Yellow Curtain";
			case 97: return "Lime Carpet";
			case 98: return "Pink Carpet";
			case 99: return "Gray Carpet";
			case 100: return "Light Gray Carpet";
			case 101: return "Cyan Carpet";
			case 102: return "Purple Carpet";
			case 103: return "Blue Carpet";
			case 104: return "Brown Carpet";
			case 105: return "Green Carpet";
			case 106: return "Red Carpet";
			case 107: return "Black Carpet";

			// Else
			default: return "Null Furniture";
		}
	}
}
